#!/usr/bin/python

# User 2%, System 4%, IOW 0%, IRQ 0%
# User 13 + Nice 0 + Sys 31 + Idle 579 + IOW 0 + IRQ 0 + SIRQ 0 = 623

import string
import os
from Myconfig import *

class ProMonitor:
        

        # VSIZE 3  RSS 4
        monitorwhat = 4
        
        ########################################################
         
	def __init__(self):
            self.name = 'Monitorlist'
            self.monitorcontainer={}
            self.namelist = [['com.jrdcom.weather',0xff0000], \
                  ['system_server',0x00ff00], \
                  ['com.gameloft.android.GAND.GloftGLIA',0x0000ff]]
            self.colors=[0xff0000,0x00ff00,0x0000ff,
                      0x778899,0x124578,0x968573,
                      0x665544,0x225544,0x335599,
                      0x565656,0x456887,0x567845]


        def  selectprosess(self):
            print self.namelist
            for index in range(0,len(self.namelist)):
                self.namelist.pop()
            print self.namelist
            print 'has empty'
            lines = os.popen('cat ./out/monitorprocess.txt').readlines()
            index=0
            for line in lines:
                line=line.strip()
                if len < 2:
                    continue
                self.namelist.insert(0,[line,self.colors[index]])
                index = index +1

            print self.namelist
                
             
        def  parse(self,s): 
            s=s.strip()
            item=string.split(s)
            
            #print  'memory'
            for process in self.namelist:
                name = process[0]
                if name in s:
                    mem = float(item[ProMonitor.monitorwhat])/1024
                    #print name
                    temp =[]
                    if self.monitorcontainer.has_key(name) :
                        self.monitorcontainer[name].append(mem)
                        if len(self.monitorcontainer[name]) > Myconfig.samplecount:
                            del self.monitorcontainer[name][0]    
                    else:
                        temp.append(mem)
                        self.monitorcontainer[name]=temp
            
                        
 





